import {createRouter,createWebHistory} from 'vue-router'
import Home from'../views/Home.vue'
import Cate from'../views/Cate.vue'
import Detail from'../views/Detail.vue'
import Add from'../views/Add.vue'
import About from'../views/About.vue'
import Login from'../views/Login.vue'
import Reg from'../views/Reg.vue'
import News from'../views/News.vue'
import Article from'../views/Article.vue'
import UserIndex from'../views/user/Index.vue'
import UserSet from'../views/user/Set.vue'
import NotFound from'../components/NotFound.vue'

// 1. Define route components.
// These can be imported from other files
// const Home = { template: '<div>Home</div>' }
// const About = { template: '<div>About</div>' }

// 2. Define some routes
// Each route should map to a component.
// We'll talk about nested routes later.
const routes = [
  { path: '/', component: Home },
  { path: '/post/list/:cate', component: Cate },
  { path: '/post/:id(\\d+)', component: Detail },
  { path: '/post/add', component: Add },
  { path: '/about', component: About },
  { path: '/login', component: Login },
  { path: '/reg', component: Reg },
  { path: '/news/:id', component: News },
  { path: '/article/:id(\\d+)', component: Article },
  { path: '/user', component: UserIndex },
  { path: '/user/set', component: UserSet },
  { path: '/:path(.*)', component: NotFound },
]

// 3. Create the router instance and pass the `routes` option
// You can pass in additional options here, but let's
// keep it simple for now.
const router = createRouter({
  // 4. Provide the history implementation to use. We are using the hash history for simplicity here.
  // history: createWebHashHistory(),
  history: createWebHistory(),
  routes, // short for `routes: routes`
})

router.beforeEach((to, from, next) => {
  // console.log(to,from)
  // return false
  next()
})

export default router